﻿using Microsoft.AspNetCore.Mvc;
using MyToDo.Content;
using MyToDo.Content.UnitOfWork;
using MyToDo.Dtos;
using MyToDo.Service;
using MyToDo.Shared.Parameters;

namespace MyToDo.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class ToDoController : Controller
    {
        private readonly IToDoService service;

        //private IUnitOfWork unitOfWork;
        //public ToDoController(IUnitOfWork unitOfWork)
        //{
        //    this.unitOfWork = unitOfWork;
        //}

        //public async Task<IActionResult> get(int id)
        //{
        //    var reposiotry = unitOfWork.GetRepository<ToDo>();
        //    var todo = await reposiotry.GetFirstOrDefaultAsync(predicate: t => t.Id.Equals(id));
        //    return null;
        //}


        public ToDoController(IToDoService service)
        {
            this.service = service;
        }
        [HttpGet]
        public async Task<ApiResponse> Get(int id) => await service.GetSingleAsync(id);

        [HttpGet]
        public async Task<ApiResponse> Summary() => await service.Summary();
        [HttpGet]
        public async Task<ApiResponse> GetAll([FromQuery] ToDoParameter query) => await service.GetAllAsync(query);
        [HttpPost]
        public async Task<ApiResponse> Add([FromBody] ToDoDto model) => await service.AddAsync(model);
        [HttpPost]
        public async Task<ApiResponse> Update([FromBody] ToDoDto model) => await service.UpdateAsync(model);
        [HttpDelete]
        public async Task<ApiResponse> Delete(int id) => await service.DeleteAsync(id);


    }
}
